<template>
    <view class="app">
        <load :ready="ready"></load>
		<view class="addres-list">
			<view class="item" @click="link(`/pages/user/addres_info`)" >
				<view class="top">
					<u-tag text="默认地址" size="mini" style="margin-right: 5px;" mode="dark" />
					<text class="name">{{userInfo.name}}</text>
					<text class="mobile">{{userInfo.telephone}}</text>
					
				</view>	
				<view class="text">{{userInfo.address}}</view>
				
				<view class="icons">
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>	
		
		<!-- <u-gap height="160"></u-gap>
		<view class="btnbox fixed">
			<u-button type="primary" @click="link(`./bill_form`)" shape="circle" :custom-style="btnStyle">添加地址</u-button>
		</view> -->
		
	</view>
</template>

<script>
import { mapState, mapActions, mapMutations, mapGetters } from 'vuex';
import { mixinsBase } from '@/common/js/mixins';
let that;
export default {
    mixins: [mixinsBase],
    components: {},
    data() {
        return {
			btnStyle:this.$config.btnStyle,
			billType: 1,
			customStyle:{
				fontSize: '13px',
				padding: '6px 15px',
				margin: '0 0 0 8px'
			},
			listTip: {},
			list:[],
			info:{},
			showDel: false,
        };
    },
    onLoad() {
        that = this;
    },
    onReady() {
    },
    onShow() {
       // this.$list.init(this);
       // this.getList();
	   this.getUserInfo();
    },
    onUnload() {
        that = null;
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        // this.getInit(data=>{
        //      uni.stopPullDownRefresh();
        //      common.showTip('刷新成功');
        // });
    },

    /**
     * 页面上拉触底事件的处理函数
     */
   onReachBottom: function() {
		// this.$list.onReachBottom(this)
   },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
        //       return {
        // 	// path,
        // 	imageUrl:config.shareImg,
        // 	// title
        // }
    },
    methods: {
		async getUserInfo(){
			let res = await this.$api.getUserList();
			if(res.data.id){
				let userInfo = {
					...this.userInfo,
					...res.data,
				}
				this.user = res.data
				this.setUserInfo(userInfo)
			}
		},
		async handleConfirmDel(){
			uni.showLoading({
				mask:true
			});
			const  res = await this.$api.billingRemove({
				id: this.info.id,
			});
			uni.hideLoading();
			if (res.data.code == this.$config.RESOK) {
				this.showDel = false;
				this.$common.showTip(res.data.msg)
				this.list.splice(this.info.index, 1)
			} else{
				this.$common.showTip(res.data.msg, 'none')
			}
		},
		handleDel(item, index){
			this.showDel = true;
			this.info = {
				...item,
				index,
			}
		},
		async getList() {
		    let listTip = this.listTip;
		    let res = {};
		    let params = {
		        pageNum: listTip.p,
		        pageSize: listTip.size,
		    };
		    try {
		        res = await this.$api.billingList(params);
		    } catch (e) {
		        uni.hideLoading();
		        console.log('err', e);
		    }
		    if (res.data.code == this.$config.RESOK) {
		        let list = res.data.rows || [];
		        let setdata = this.$list.normalData(list, this);
				console.log(setdata);
		        this.list = setdata.list;
		        this.listTip = setdata.listTip;
		        if (setdata.list.length >= res.data.total && listTip.p > 1 || !list.length) {
		            this.$list.notdata(this);
		        } 
		    } 
		},
       ...mapActions(['setUserInfo']),
    },
    computed: {
        ...mapState({
            userInfo: 'userInfo'
        })
    }
};
</script>

<style scoped lang="scss">
page {
    background-color: #F8FAFD;
}
.addres-list{
	.item{
		background: #fff;
		margin-bottom: 12px;
		padding:  30rpx;
		border: 2px solid #fff;
		overflow: hidden;
		position: relative;
		border-bottom: 1px solid #ddd;
	}
	.icons{
		position: absolute;
		right: 10px;
		top: 50%;
	}
	.top{
		margin-bottom: 5px;
		display: flex;
	}
	.name{
		margin-right: 10px;
	}
	.mobile{
		flex: 1;
	}
	.tip{
		color: $color;
		font-size: 13px;
	}
	.text{
		color: #666;
	}
}
</style>
